package com.mio.web.controller.util;

import java.util.List;

import org.durcframework.core.controller.CrudController;
import org.durcframework.core.controller.SearchController;
import org.durcframework.core.expression.ExpressionQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mio.web.entity.auth.AuthSystemResource;
import com.mio.web.entity.user.User;
import com.mio.web.service.auth.AuthSystemResourceService;
import com.mio.web.util.TreeUtil;

@Controller
public class TreeController extends SearchController<AuthSystemResource, AuthSystemResourceService> {

	@RequestMapping("/listUserMenu.do")
	public @ResponseBody Object listUserMenu(User entity) {
		ExpressionQuery query = new ExpressionQuery();
		query.setIsQueryAll(true);
		List<AuthSystemResource> list = this.getService().find(query);

		list = TreeUtil.buildTreeData(list);

		return list;
	}
	
	/**
	 * 此方法是为了解决服务器上调用的
	 * @param entity
	 * @return
	 */
	@RequestMapping("/manager/listUserMenu.do")
	public @ResponseBody Object listUserMenu2(User entity) {
		ExpressionQuery query = new ExpressionQuery();
		query.setIsQueryAll(true);
		List<AuthSystemResource> list = this.getService().find(query);

		list = TreeUtil.buildTreeData(list);

		return list;
	}
}
